package com.da.springtest.other.lazy;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;

@Lazy
@Configurable
public class MainConfig1 {

    @Bean
    public String name() {
        System.out.println("create bean:name");
        return "Joker";
    }

    @Bean
    public String address() {
        System.out.println("create bean:address");
        return "长沙市";
    }

    @Bean
    @Lazy(false)
    public Integer age() {
        System.out.println("create bean:age");
        return 30;
    }

    public static void main(String[] args) {
        System.out.println("准备启动spring容器");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig1.class);
        System.out.println("spring容器启动完毕");

        for (String beanName : Arrays.asList("name", "age", "address")) {
            System.out.println("----------");
            System.out.println("getBean:" + beanName + ",start");
            System.out.println(String.format("%s->%s", beanName, context.getBean(beanName)));
            System.out.println("getBean:" + beanName + ",end");
        }
    }
}